//
//  shaders.metal
//  learn-metal
//
//  Created by LimitLiu on 2019/1/25.
//  Copyright © 2019 LimitLiu. All rights reserved.
//

#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

typedef struct {
    vector_float2 position;
    vector_float4 color;
} Vertex;

typedef struct {
    float4 clipSpacePosition [[position]];
    float4 color;
} RasterizerData;

vertex RasterizerData vertexShader(uint vertexId [[vertex_id]], constant Vertex *vertices [[buffer(0)]]) {
    RasterizerData out;
    out.clipSpacePosition = vector_float4(0.0, 0.0, 0.0, 1.0);
    float2 pixelsSpacePosition = vertices[vertexId].position.xy;
    out.clipSpacePosition.xy = pixelsSpacePosition;
    out.color = vertices[vertexId].color;
    return out;
}

fragment float4 fragmentShader(RasterizerData in [[stage_in]]) {
    return in.color;
}
